﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Common;
using System.Linq;
using System.Text;

namespace Wjtour.BLL
{
    public class hotelpicture_bll : base_dll
    {
        public Wjtour.Domain.hotelpicture Load(int id)
        {
            string sql = "select * from hotelpicture where id=" + id;
            return DbAccess.GetObjects<Wjtour.Domain.hotelpicture>(sql).FirstOrDefault();
        }

        public bool Save(Wjtour.Domain.hotelpicture entity)
        {
            string sql = "";

            DbCommand cmd = DbAccess.CreateCommand();

            if (entity.id > 0)
            {
                sql = @"UPDATE hotelpicture SET 
            hotelid = @hotelid,
            pictureid = @pictureid,
            addtime = @addtime
             WHERE id=@id";
                DbAccess.AddInParameter(cmd, "@id", DbType.Int32, entity.id);

            }
            else
            {
                sql = @"INSERT INTO hotelpicture( 
                hotelid,pictureid,addtime)VALUES(
                @hotelid,@pictureid,@addtime)";
            }
            DbAccess.AddInParameter(cmd, "@hotelid", DbType.Int32, entity.hotelid);
            DbAccess.AddInParameter(cmd, "@pictureid", DbType.Int32, entity.pictureid);
            DbAccess.AddInParameter(cmd, "@addtime", DbType.DateTime, entity.addtime);
            cmd.CommandText = sql;
            cmd.CommandType = System.Data.CommandType.Text;
            return DbAccess.ExecuteNonQuery(cmd) > 0;

        }

        public int BatchDelete(string ids)
        {
            string sql = "delete from hotelpicture where id in(" + ids + ")";
            return DbAccess.ExecuteNonQuery(sql);
        }
    }
}
